﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using Online_Shopping_System;
using RBOSS.Business.CustomerModule;
using RBOSS.Business.ShoppingCarts;

namespace RBOSS.WebUI.Models
{
    public abstract class MasterSite:Page
    {
        private Site1 _master;

        protected override void OnLoad(EventArgs e)
        {
            _master = (Site1)Page.Master;
            _master.CheckoutClick += InvokeCheckoutClick;
            
            base.OnLoad(e);
        }

        protected virtual void InvokeCheckoutClick(object sender, EventArgs e)
        {
            
        }

        protected void ShowCheckoutButton(bool value)
        {
            _master.ShowCheckoutButton(value);
        }

        protected override void OnLoadComplete(EventArgs e)
        {
            var shoppingCart = CustomerSingleton.GetShoppingCart();
            var products = shoppingCart.GetProducts();
            _master.SetAmountInCart(products.Sum(p=>p.Qunatity));
            _master.SetTotalPrice(products.Sum(p => p.Total));

            base.OnLoadComplete(e);
        }

        
    }
}